/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MODEL.DAO;

import MODEL.POJO.LocSanPhamPOJO;
import MODEL.UTIL.MySqlDataAccessHelper;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author linh
 */
public class LocSanPhamDAO {
    
    public static ArrayList<LocSanPhamPOJO> LayLoctenmuc(String idloaisanpham){
        ArrayList<LocSanPhamPOJO> dslsp= new ArrayList<LocSanPhamPOJO>();
        String sql = String.format("SELECT DISTINCT TENMUC FROM LOCSANPHAM WHERE IDLOAISANPHAM='%s'",idloaisanpham);
        try{
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.Open();
            ResultSet rs=helper.executeQuery(sql);
            while(rs.next()){
                LocSanPhamPOJO lsp=new LocSanPhamPOJO();
                lsp.setTenmuc(rs.getString("tenmuc"));
                dslsp.add(lsp);                
            }            
        }catch(SQLException ex){
            System.out.println(ex.getMessage());
        }
        return dslsp;
    }
    
        public static ArrayList<LocSanPhamPOJO> LayLocsp(String tenmuc){
        ArrayList<LocSanPhamPOJO> dslsp= new ArrayList<LocSanPhamPOJO>();
        String sql = String.format("SELECT * FROM LOCSANPHAM WHERE TENMUC='%s'",tenmuc);
        try{
            MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
            helper.Open();
            ResultSet rs=helper.executeQuery(sql);
            while(rs.next()){
                LocSanPhamPOJO lsp=new LocSanPhamPOJO();
                lsp.setIdloaisanpham(rs.getString("idloaisanpham"));
                lsp.setIdsanpham(rs.getString("idsanpham"));
                lsp.setTenmuc(rs.getString("tenmuc"));
                lsp.setTensploc(rs.getString("tensploc"));
                dslsp.add(lsp);                
            }            
        }catch(SQLException ex){
            System.out.println(ex.getMessage());
        }
        return dslsp;
    }
}